﻿using System;
using System.Web.UI.WebControls;

namespace ControlExplorer.samples.EditModeFormat
{
  public partial class Overview : SpreadDemoPage
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      if (IsPostBack)
      {
        return;
      }

      InitSpread(FpSpread1);
      InitSpreadStyles(FpSpread1.Sheets[0]);
      this.FpSpread1.UseClipboard = false;
    }

    private void InitSpread(FarPoint.Web.Spread.FpSpread spread)
    {
      spread.CssClass = "spreadStyle";
      spread.UseClipboard = false;
    }

    private void InitSpreadStyles(FarPoint.Web.Spread.SheetView sheet)
    {
      sheet.ColumnCount = 4;
      sheet.RowCount = 4;

      sheet.ColumnHeader.Cells[0, 0].Value = "单元格类型";
      sheet.ColumnHeader.Cells[0, 1].Value = "显示格式";
      sheet.ColumnHeader.Cells[0, 2].Value = "编辑格式";
      sheet.ColumnHeader.Cells[0, 3].Value = "输入列";

      FarPoint.Web.Spread.CurrencyCellType cct = new FarPoint.Web.Spread.CurrencyCellType();
      cct.NumberFormat = new System.Globalization.NumberFormatInfo();
      cct.NumberFormat.CurrencySymbol = "USD";

      cct.EditMode.NumberFormat = new System.Globalization.NumberFormatInfo();
      cct.EditMode.NumberFormat.CurrencySymbol = "$";

      sheet.Cells[0, 0].Value = "货币单元格类型";
      sheet.Cells[0, 1].Value = "货币符：USD";
      sheet.Cells[0, 2].Value = "货币符号：$";
      sheet.Cells[0, 3].CellType = cct;
      sheet.Cells[0, 3].Value = 12345;

      FarPoint.Web.Spread.DateTimeCellType dct = new FarPoint.Web.Spread.DateTimeCellType();
      //dct.DateTimeFormat = new System.Globalization.DateTimeFormatInfo();
      dct.FormatString = "MMMM dd, yyyy";

      dct.EditMode.DateTimeFormat = new System.Globalization.DateTimeFormatInfo();
      dct.EditMode.FormatString = "MM/dd/yyyy";

      sheet.Cells[1, 0].Value = "日期单元格类型";
      sheet.Cells[1, 1].Value = "格式：MMMM dd, yyyy";
      sheet.Cells[1, 2].Value = "格式：MM/dd/yyyy";
      sheet.Cells[1, 3].CellType = dct;
      sheet.Cells[1, 3].Value = DateTime.Now;
      sheet.Cells[1, 3].HorizontalAlign = HorizontalAlign.Right;

      FarPoint.Web.Spread.DoubleCellType dbct = new FarPoint.Web.Spread.DoubleCellType();
      dbct.NumberFormat = new System.Globalization.NumberFormatInfo();
      dbct.NumberFormat.NumberDecimalSeparator = ".";

      dbct.EditMode.NumberFormat = new System.Globalization.NumberFormatInfo();
      dbct.EditMode.NumberFormat.NumberGroupSizes = new int[] { 0 };

      sheet.Cells[2, 0].Value = "双精度单元格类型";
      sheet.Cells[2, 1].Value = "有分组符";
      sheet.Cells[2, 2].Value = "无分组符号";
      sheet.Cells[2, 3].CellType = dbct;
      sheet.Cells[2, 3].Value = 12345.6d;

      FarPoint.Web.Spread.IntegerCellType ict = new FarPoint.Web.Spread.IntegerCellType();
      ict.NumberFormat = new System.Globalization.NumberFormatInfo();
      ict.NumberFormat.NegativeSign = "~";

      ict.EditMode.NumberFormat = new System.Globalization.NumberFormatInfo();
      ict.EditMode.NumberFormat.NegativeSign = "@";

      sheet.Cells[3, 0].Value = "整形单元格类型";
      sheet.Cells[3, 1].Value = "负号：~";
      sheet.Cells[3, 2].Value = "负号：@";
      sheet.Cells[3, 3].CellType = ict;
      sheet.Cells[3, 3].Value = -12;

      sheet.Columns[0].Width = 140;
      sheet.Columns[1].Width = 150;
      sheet.Columns[2].Width = 140;
      sheet.Columns[3].Width = 150;

      sheet.Cells[0, 0].Locked = true;
      sheet.Cells[0, 1].Locked = true;
      sheet.Cells[0, 2].Locked = true;
      sheet.Cells[1, 0].Locked = true;
      sheet.Cells[1, 1].Locked = true;
      sheet.Cells[1, 2].Locked = true;
      sheet.Cells[2, 0].Locked = true;
      sheet.Cells[2, 1].Locked = true;
      sheet.Cells[2, 2].Locked = true;
      sheet.Cells[3, 0].Locked = true;
      sheet.Cells[3, 1].Locked = true;
      sheet.Cells[3, 2].Locked = true;
      sheet.LockBackColor = System.Drawing.Color.FromArgb(184, 184, 184);
    }

  }
}